<!DOCTYPE html>
<html lang="en">
<title>低价包邮</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-ms/minireset.css/0.0.2/minireset.css">
<link rel="stylesheet" href="https://at.alicdn.com/t/font_1534407_cqy0t98abrg.css">
<link rel="stylesheet" href="https://img.bc.haodanku.com/cdn/vant_2.12.min.css">
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-ms/promise-polyfill/8.2.0/polyfill.min.js"></script>
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-ms/jquery/2.2.4/jquery.min.js"></script>
<script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-ms/vue/2.6.10/vue.min.js"></script>
<script src="https://img.bc.haodanku.com/cdn/vant_2.12.min.js"></script><!--pc端click代替touch-->
<script src="https://img.bc.haodanku.com/cdn/touch-emulator.js"></script>
<script src="https://img.bc.haodanku.com/cms/utils.v1_0_5.js"></script>
<body>
<script
  defer>document.write("<link rel=\"stylesheet\" href=\"https://img.bc.haodanku.com/cms/lowprice.css?t=" + (Date.now() - Date.now() % (60 * 1000 * 30)) + "\"/>");</script>
<template id="c-list-item">
  <div class="goods-card">
    <img v-lazy="item.itempic" v-if="item.itempic">
    <img src="http://img.bc.fqapps.com/fudai13cae4ae6ef16739ed3b100a2ec39e97.gif" alt="" v-else>
    <div class="detail">
      <div class="title">
        <template v-if="'jd' !== type">
          <img
            v-if="item.shoptype === 'B'"
            class="icon tm"
            src="http://img-haodanku-com.cdn.fudaiapp.com/FvU9Lg74-WgBzWQphv98-9KgYF6d"
            alt="">
          <img
            v-else-if="item.shoptype === 'C'"
            class="icon tb"
            src="http://img-haodanku-com.cdn.fudaiapp.com/FnCy1eY4W5khYdTw_iIDhKuwGLmu"
            alt="">
        </template>
        <img
          v-else
          class="icon"
          src="http://img-haodanku-com.cdn.fudaiapp.com/FieNXmZjc_io1YMTcsCbrxsQJBR0"
          alt="">
        <!-- <img
           v-else-if="'tm' === type"
           class="icon"
           src="http://img-haodanku-com.cdn.fudaiapp.com/FtThlDILaSzwEIAIvFYK3iIDJv4-"
           alt="">-->
        <span>{{ item.itemtitle }}</span>
      </div>
      <div class="tm-icons" v-if="false">
        <img
          v-if="item.shoptype === 'B'"
          class="icon tm"
          src="http://img-haodanku-com.cdn.fudaiapp.com/FvU9Lg74-WgBzWQphv98-9KgYF6d"
          alt="">
        <img
          v-else-if="item.shoptype === 'C'"
          class="icon tb"
          src="http://img-haodanku-com.cdn.fudaiapp.com/FnCy1eY4W5khYdTw_iIDhKuwGLmu"
          alt="">
      </div>
      <div class="center">
        <div class="price" v-bind:class="{'has-share': showShare}">
          <div class="discount">{{type !== "jd" ? "券后" : "礼金"}}价：<strong>{{ Number(item.itemendprice) }}元</strong></div>
          <div class="price-bottom">
            <div class="origin">原价：{{ item.itemprice }}元</div>
            <div class="sales" v-show="!showShare"><span class="name">月销</span><span
              class="value">{{item.itemsale}}</span></div>
          </div>
        </div>
        <span v-if="showShare" class="share" v-bind:id="'item' + item.sku"
              v-on:click.capture="share($event,item)">分享</span>
      </div>
      <div class="footer">
        <div class="ticket">
          <span class="name">券</span><span
          class="value">￥{{ type !== "jd" ? item.couponmoney : item.coupon_amount }}</span>
        </div>
        <span v-if="item.stock == 0" class="operation sell-out">已抢完</span>
        <span v-else-if="item.stock == -1" class="operation sell-out">未开始</span>
        <span v-else class="operation" v-on:click.capture="buy($event,item)">立即购买</span>
      </div>
    </div>
  </div>
</template>
<script>
Vue.component("list-item", {
  template: "#c-list-item",
  props: {
    item: Object,
    type: {
      type: String,
      default: "tb" // tb || jd
    },
    showShare: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    share: function(e, item) {
      this.$emit("share", e, item);
    },
    buy: function(e, item) {
      this.$emit("buy", e, item);
    }
  }
});
</script>
<template id="c-share">
  <div class="free-share">
    <div id="share_href" v-on:click="handleShare">
      <i>
        <svg xmlns="http://www.w3.org/2000/svg" id="svg-icon" data-name="图层 1" viewBox="0 0 18 19.11">
          <title>分享</title>
          <path class="cls-1" d="M17.5,8A2.5,2.5,0,1,0,15,5.5,2.5,2.5,0,0,0,17.5,8Z" transform="translate(-3 -2)"/>
          <path class="cls-1" d="M6.5,14.5A2.5,2.5,0,1,0,4,12,2.5,2.5,0,0,0,6.5,14.5Z" transform="translate(-3 -2)"/>
          <path class="cls-2" d="M15,6.79,8.67,10.62" transform="translate(-3 -2)"/>
          <path class="cls-2" d="M8.67,13.28,13.27,16" transform="translate(-3 -2)"/>
          <path class="cls-1" d="M15.77,15.11a2.5,2.5,0,1,1-2.5,2.5A2.5,2.5,0,0,1,15.77,15.11Z"
                transform="translate(-3 -2)"/>
        </svg>
      </i>
      <span>分享好友</span>
    </div>
  </div>
</template>
<script>
Vue.component("share", {
  template: "#c-share",
  methods: {
    handleShare: function() {
      this.$emit("share");
    }
  }
});
</script>
<template id="c-loading">
  <!-- 加载效果 -->
  <div class="free-loading">
    <div class="la-line-scale">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
    <p>数据加载中...</p>
  </div>
</template>
<script>
Vue.component("loading", {
  template: "#c-loading"
});
</script>

<div class="free-container" id="free_app" v-cloak>
  <div class="free-mail"><img class="free-banner banner" v-bind:src="banner" alt="">
    <div class="free-navbar">
      <div class="free-navbar-class"><span class="active-bg"
                                           v-bind:style="{left:(switchData.activeIndex / switchData.list.length * 100) + '%',width:(100/switchData.list.length)+'%'}"></span><span
        v-for="(item, index) in switchData.list" v-bind:class="{'active': item.value == switchData.selected}"
        v-on:click="handleNavbar(item, index)">{{ item.name }}</span></div>
    </div>
    <div class="free-lists">
      <template v-if="listData.list.length || listData.finished">
        <list-item class="free-item" v-for="(item,index) in listData.list" v-bind:item="item" v-bind::key="index"
                   v-on:buy="handleGoodsTransfer"></list-item><!-- 底部提示 -->
        <div class="goods-card-loading"><span v-if="listData.finished">已经加载到底啦~</span><span v-else>数据正在赶来的路上...</span>
        </div>
      </template><!-- 加载效果 -->
      <loading v-else-if="!listData.list.length &amp;&amp; listData.loading"></loading>
    </div>
  </div>
  <div class="back-top-wrap max-width">
    <div class="btn back-top" v-on:click="backTop" v-bind:class="{hide: scrollTop &lt; 600}"></div>
  </div>
  <share v-on:share="handleShare" v-bind:class="{hide:isScrollToDown}"></share>
</div>
<script>
Vue.use(vant.Lazyload, {
  preLoad: 1.3,
  error: "http://img.bc.haodanku.com/haodanku/1595237918",
  loading: "http://img.bc.fqapps.com/fudai13cae4ae6ef16739ed3b100a2ec39e97.gif",
  attempt: 1
});

var listDataStr = JSON.stringify({
  list: [],
  loading: false,
  finished: false,
  min_id: 1,
  pageTotal: 1,
  pageCurrent: 0
});


// 根据微信浏览器缩放比例设置rem缩放
if(inWechat() && "ontouchstart" in window) {
  const scale = getFontScale(true);
  document.documentElement.style.fontSize =
    "calc(13.33333vw * " + scale + ")";
}


var baseMixin = {
  el: "#single-page-app",
  data: function() {
    return {
      listData: JSON.parse(listDataStr),
      scrollTop: 0,
      isScrollToDown: false
    };
  },
  created: function() {
    this.getListData();
  },
  watch: {
    scrollTop: function(n, o) {
      this.isScrollToDown = n > o;
    }
  },
  mounted: function() {
    var that = this;
    window.addEventListener("scroll", function(ev) {
      that.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
      if(isScrollEnd(this, "vertical", 40)) {
        that.onScrollEnd();
      }
    });
  },
  methods: {
    onScrollEnd: function() {
      this.getListData();
    },
    resetListData: function() {
      this.listData = JSON.parse(listDataStr);
    },
    getListDataParams: function(item) {
      throw new Error("需要使用了该mixins的组件实现listDataParams函数");
    },
    getListData: function() {
      throw new Error("需要使用了该mixins的组件实现getListData函数");
    },
    getTransferParams: function() {
      throw new Error("需要使用了该mixins的组件实现transferParams函数");
    },
    handleGoodsTransfer: function() {
      throw new Error("需要使用了该mixins的组件实现handleGoodsTransfer函数");
    },
    /**
     * 分享给好友
     */
    handleShare: function() {
      copy(location.href, "复制成功，分享给身边好友吧~");
    }
  }
};
var vmUrlSearchs;
window.vmRequest = function(name) {
  if(!vmUrlSearchs) {
    vmUrlSearchs = new vmUrlSearch();
  }
  return vmUrlSearchs[name];
};
window.vmUrlSearch = function() {
  var name, value;
  var str = location.href;
  var num = str.indexOf("?");
  str = str.substr(num + 1);
  var arr = str.split("&");
  for(var i = 0; i < arr.length; i++) {
    num = arr[i].indexOf("=");
    if(num > 0) {
      name = arr[i].substring(0, num);
      value = arr[i].substr(num + 1);
      this[name] = value;
    }
  }
};

var indexMixin = {
  mixins: [baseMixin],
  el: "#free_app",
  data: function() {
    return {
      vmCid: parseSearch().cid,
      hostLink: window.location,
      vmHttp: (function() {
        var protocol = window.location.protocol;
        protocol = protocol.substring(0, protocol.length - 1);
        return protocol.includes("http") ? protocol : "http";
      })(),
      switchData: {
        list: [
          {
            name: "9元专区",
            value: 2
          },
          {
            name: "6元专区",
            value: 3
          },
          {
            name: "3元专区",
            value: 4
          }
        ],
        selected: 2,
        activeIndex: 0
      },
      banner: "http://img-haodanku-com.cdn.fudaiapp.com/FtGOXtB2bib_pV3CQidX1x_mRBwi"
    };
  },
  methods: {
    backTop() {
      $("html,body").animate({scrollTop: 0});
    },
    /**
     * 切换导航栏
     */
    handleNavbar: function(item, index) {
      if(this.listData.loading || this.switchData.activeIndex === index) return;
      this.switchData.activeIndex = index;
      this.switchData.selected = item.value;
      this.resetListData();
      this.getListData();
    },
    /**
     * 获取商品数据
     */
    getListData: function() {
      if(this.listData.loading || this.listData.finished) return;
      var that = this;
      that.listData.loading = true;
      $.ajax({
        url: this.vmHttp + "://v2.api.haodanku.com/low_price_Pinkage_data",
        type: "GET",
        data: Object.assign(
          {
            type: this.switchData.selected,
            min_id: this.listData.min_id
          },
          this.getListDataParams()
        ),
        dataType: "json",
        error: function(e) {
          toast("网络错误，请检查网络重试");
        }
      }).done(function(res) {
        if(Number(res.code) !== 1) {
          toast(res.msg);
          return;
        }
        that.listData.min_id = res.min_id;
        setTimeout(function() {
          that.listData.list = that.listData.list.concat(res.data);
          that.listData.loading = false;
          that.listData.finished = !Boolean(res.data && res.data.length);
        }, 200);
      });
    },
    /**
     * 商品转链
     */
    handleGoodsTransfer: function(e, item) {
      if(item.stock == 0) {
        toast("已抢完");
        return;
      } else if(item.stock == -1) {
        toast("活动未开始");
        return;
      }
      var that = this;
      Request.postSync(
        this.getTransferUrl(),
        Object.assign(
          {
            type: this.switchData.selected,
            itemid: item.itemid,
            title: item.itemshorttitle
          },
          this.getTransferParams(item)
        ),
        function(res) {
          if(res.code == 200 || res.code === 1) {
            that.resolveTransferRes(e, res);
          } else {
            toast(res.msg);
          }
        });
    }
  }
};


</script>
<script>
var customParams = {
  apikey: "sylar", //必填
  pid: "mm_1520060136_2232550319_111181400478",//必填
  tb_name: "tb370655212"//必填
};
new Vue({
  mixins: [indexMixin],
  methods: {
    getTransferUrl: function() {
      return url("v2.api.haodanku.com/ratesurl");
    },
    getListDataParams: function() {
      return {apikey: customParams.apikey};
    },
    getTransferParams: function() {
      return {
        apikey: customParams.apikey,
        pid: customParams.pid,
        tb_name: customParams.tb_name,
        get_taoword: 1
      };
    },
    resolveTransferRes: function(e, res) {
      if(inWechat()) {
        e.target.parentNode.addEventListener("click", function() {
          copy("0" + res.data.taoword + "/", "复制淘口令成功，请打开淘宝领取");
        });
        return;
      }
      vant.Dialog.confirm({
        message: "是否跳转到下单页面?"
      }).then(function() {
        window.top.location = res.data.item_url;
      });
    }
  }
});
</script>
</body>
</html>